<?php
/* 
 * Web Gallery (FST additional functions)
 * Abe Yang <abeyang@cal.berkeley.edu> (c) 2008
 * http://code.google.com/p/flickrsetsbytag/
 *
/* ---------------------------------------------------------------------------------- */

require('../fst.class.php');

// $data must be unserialized array (album or albumlist, etc)
function toJSON($data) { 
	$json = '{';
	foreach ($data as $k => $v) {
		if (is_array($v)) $str = photostoJSON($v);
		else {
			$v = str_replace("\n", '<br />', $v);
			$str = '"' . $v . '"';
		}
		$json .= $k . ': ' . $str . ', ';
	}
	$json = substr($json, 0, -2) . '}';
	return $json;
}	// end toJSON()

function photostoJSON($photos) {
	$json = '[';
	foreach ($photos as $photo) {
		$str = toJSON($photo);
		$json .= $str . ', ';
	}
	$json = substr($json, 0, -2) . ']';
	return $json;
}

?>